<template>
	<view class="container">
		<Header>
			<image src="https://zhzx.on-line-demo.com/image/logo.png" mode="heightFix" class="logo"></image>
			<view class="text">澄迈县智慧政协</view>
		</Header>
		<view class="top-search">
			<view class="search-bar" style="width: calc(100% - 20px);" @click.stop="showSearch">
				<uni-search-bar clearButton="auto" cancelButton="none" placeholder="热门搜索"
					@focus="showSearch"></uni-search-bar>
			</view>
			<uni-icons type="scan" size="30" color="#000" @click="scanCode"></uni-icons>
		</view>
		<liuyuno-tabs :tabData="tabs" :defaultIndex="defaultIndex" @tabClick='tabClick' />
		<view style="height: calc(100vh - 206px - var(--status-bar-height))">
			<News v-if="defaultIndex == 0"></News>
			<Notice v-if="defaultIndex == 1"></Notice>
			<HotTopics v-if="defaultIndex == 2"></HotTopics>
			<MeetingDynamics v-if="defaultIndex == 3"></MeetingDynamics>
		</view>
		<Footer :idx="1"></Footer>
	</view>
</template>

<script>
import Header from '../components/header.vue'
import Footer from '../components/footer.vue'
import liuyunoTabs from "@/components/liuyuno-tabs/liuyuno-tabs.vue";
import News from './news.vue'
import Notice from './notice.vue'
import HotTopics from './hotTopics.vue'
import MeetingDynamics from './meetingDynamics.vue'
import request from '../common/request';
import signIn from '../common/signIn.js'
export default {
	components: {
		Header,
		Footer,
		liuyunoTabs,
		News,
		Notice,
		HotTopics,
		MeetingDynamics
	},
	data() {
		return {
			tabs: ['资讯', '通知公告', '热点专题', '会务动态'],
			defaultIndex: 0,
			id: ''
		}
	},
	onLoad(option) {
		this.id = option.meet_id
	},
	mounted() {
		if (this.id) signIn(this.id)
	},
	methods: {
		getUrlParams(href, name) {
			var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
			if (reg.test(href)) {
				return unescape(RegExp.$2.replace(/\+/g, " "))
			};
			return "";
		},
		scanCode() {
			let userInfo = uni.getStorageSync('userInfo')
			if (!userInfo) {
				uni.navigateTo({
					url: '/pages/login'
				})
				return false
			}
			uni.scanCode({
				success: (res) => {
					// console.log('条码类型：' + res.scanType);
					console.log(res);
					let id = this.getUrlParams(res.path, 'meet_id')
					let type = this.getUrlParams(res.path, 'codeType')
					signIn(id, type)
				}
			});
		},
		showSearch() {
			uni.navigateTo({
				url: '/pages/search'
			})
		},
		tabClick(index) {
			this.defaultIndex = index
		}
	}
}
</script>

<style scoped>
.container {
	height: 100%;
}

.logo {
	height: 20px;
	max-width: 20px;
	margin-right: 6px;
	vertical-align: middle;
	display: inline-block;
}

.text {
	display: inline-block;
	vertical-align: middle;
}

.top-search {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding-right: 10px;
}

::v-deep .uni-searchbar__box {
	border: 1px solid #898989;
	background-color: transparent !important;
	border-radius: 10px !important;
	justify-content: start !important;
}
</style>